from langchain_community.agent_toolkits import PlayWrightBrowserToolkit
from langchain_community.tools.playwright.utils import create_sync_playwright_browser
from langchain_core.tools import BaseTool
from playwright.sync_api import Browser


def get_browser(browser:Browser|None)->(list[BaseTool],Browser):
    if browser is None:
        sync_browser = create_sync_playwright_browser()
    else:
        sync_browser = browser
    toolkit = PlayWrightBrowserToolkit.from_browser(sync_browser=sync_browser)
    tools = toolkit.get_tools()

    return (tools,sync_browser)